﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter23.Examples
{
    public class Code04
    {
        public static void Begin()
        {
            {
                string[] names = { "Alonso", "Zheng", "Smith", "Jones", "Smythe", "Small", "Ruiz", "Hsieh", "Jorgenson", "Ilyich", "Singh", "Samba", "Fatimah" };
                var queryResults =
                    from n in names
                    where n.StartsWith("S")
                    orderby n descending
                    select n;
                Console.WriteLine("Names beginning with S:");
                foreach (var item in queryResults)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("Program finished, press Enter Return to continue:");
                Console.ReadLine();
            }
            {
                string[] names = { "Alonso", "Zheng", "Smith", "Jones", "Smythe", "Small", "Ruiz", "Hsieh", "Jorgenson", "Ilyich", "Singh", "Samba", "Fatimah" };
                var queryResults =
                    from n in names
                    where n.StartsWith("S")
                    orderby n.Substring(n.Length - 1)
                    select n;
                Console.WriteLine("Names beginning with S:");
                foreach (var item in queryResults)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("Program finished, press Enter Return to continue:");
                Console.ReadLine();
            }
        }
    }
}
